package susebs.pb.travel_server.controller;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import susebs.pb.travel_server.domain.Result;
import susebs.pb.travel_server.utils.DataInit.HotelsData;
import susebs.pb.travel_server.utils.DataInit.LandmarksData;
import susebs.pb.travel_server.utils.MapInfoBasicUtil;

/**
 * 管理员:数据导入控制层
 */
@RestController
@RequestMapping("/dataInit")
@CrossOrigin
public class DataInitController {

    /**
     * 输入城市名,导入对应城市景区数据
     * @param city 景区所属城市
     * @return 是否导入成功
     */
    @GetMapping("/landmarksInit")
    public Result landmarksInit(String city) throws Exception {
        try {
            LandmarksData.LandmarksDataInit(MapInfoBasicUtil.getAddr("景区",city));
            return Result.buildSuccess();
        }catch (Exception e){
            return Result.buildFail("数据部分导入失败,可能是爬取数据缺失,请换个城市爬取!");
        }
    }

    /**
     * 输入城市名,导入对应城市酒店数据
     * @param city 酒店所属城市
     * @return 是否导入成功
     */
    @GetMapping("/hotelsInit")
    public Result hotelsInit(String city) throws Exception {
        try {
            HotelsData.hotelDataInit(MapInfoBasicUtil.getAddr("酒店",city));
            return Result.buildSuccess();
        }catch (Exception e){
            return Result.buildFail("数据部分导入失败,可能是爬取数据缺失,请换个城市爬取!");
        }
    }






}
